﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.TestDrivens;

namespace Pixysoft.Framework.Configurations.Core
{
    class HtmlDocument : IHtmlDocument
    {
        List<IHtmlNode> list = new List<IHtmlNode>();

        public IHtmlNodeCollection Node
        {
            get
            {
                return new HtmlNodeCollection(list, StringHelper.default_html_pathspliter, 0);
            }
        }

        public IHtmlNodesCollection Nodes
        {
            get
            {
                return new HtmlNodesCollection(list, StringHelper.default_html_pathspliter, 0);
            }
        }

        public string Serialize()
        {
            StringBuilder builder = new StringBuilder();

            foreach (IHtmlNode node in list)
            {
                builder.Append(node.Serialize());
            }

            return builder.ToString();
        }

        public string Serialize(bool indent)
        {
            FormatStringBuilder builder = new FormatStringBuilder();

            foreach (IHtmlNode node in list)
            {
                builder.AppendLine(node.Serialize(indent).Trim());
            }

            return builder.ToString();
        }

        public string SerializeToLayout()
        {
            FormatStringBuilder builder = new FormatStringBuilder();

            foreach (IHtmlNode node in list)
            {
                builder.AppendLine(node.SerializeToLayout().Trim());
            }

            return builder.ToString();
        }

        public IHtmlTableCollection Tables
        {
            get
            {
                return new HtmlTableCollection(Nodes, StringHelper.default_html_pathspliter, 0);
            }
        }

        public IHtmlDivCollection Divs
        {
            get
            {
                return new HtmlDivCollection(Nodes, StringHelper.default_html_pathspliter, 0);
            }
        }
    }
}
